<template>

  <div >
    <!-- 顶部用户信息 -->
    <div class="m-profile">
      <div class="g-row">
        <div class="left">
          <img class="avatar" src="//yanxuan.nosdn.127.net/8945ae63d940cc42406c3f67019c5cb6.png" />
          <div class="info">
            <p class="one">{{userInfo.nickName}}</p>
            <p>普通用户</p>
          </div>
        </div>
        <div class="right"></div>
      </div>
    </div>
    <!-- 中间部分 -->
    <div class="middle">
      <div class="my">
        我的资产
        <hr />
      </div>
      <ul>
        <li>
          <p>￥0</p>
          <p>余额</p>
        </li>
        <li>
          <p>0</p>
          <p>红包</p>
        </li>
        <li>
          <p>0</p>
          <p>优惠卷</p>
        </li>
        <li>
          <p>0</p>
          <p>积分</p>
        </li>
        <li>
          <p>0</p>
          <p>礼品卡</p>
        </li>
      </ul>
      <div class="home">
       
      </div>
      <van-grid :column-num="3">
          <van-grid-item v-for="(item, index) in arr" :key="index" :icon="item.icon" :text="item.text" />
      </van-grid>

      <div class="bottom">
      </div>
      <div class="but"><van-button type="default" @click="logout" size="large">退出登录</van-button></div>
      <div class="last">
      </div>
    </div>
  </div>
  <div style="height: 60px;"></div>

</template>

<script lang="ts">
import { defineComponent } from "vue"
export default defineComponent({

  name: 'User',
})
</script>
<script lang="ts" setup>
import { ref } from 'vue'
import { useUserInfoStore } from '@/stores/user';
import { storeToRefs } from 'pinia';
import { useRouter } from 'vue-router'
const userInfoStore = useUserInfoStore()
const {userInfo} = storeToRefs(userInfoStore)
const router = useRouter()
//定义一个循环的数组
const arr = ref(
  [
    { icon: 'balance-list-o', text: '我的订单' },
    { icon: 'user-circle-o', text: '账号管理' },
    { icon: 'phone-circle-o', text: '我的手机号' },
    { icon: 'calendar-o', text: '周六一起拼' },
    { icon: 'vip-card-o', text: '售后服务' },
    { icon: 'cash-back-record', text: '邀请返利' },
    { icon: 'bag-o', text: '优先购' },
    { icon: 'gold-coin-o', text: '积分中心' },
    { icon: 'diamond-o', text: '会员俱乐部' },
    { icon: 'wap-home-o', text: '地址管理' },
    { icon: 'sign', text: '支付安全' },
    { icon: 'service-o', text: '帮助与客服' },
    { icon: 'comment-o', text: '意见反馈' },
    { icon: 'miniprogram-o', text: '我的竞拍' },
  ]
)
//退出登录
async function logout(){
 try {
    await userInfoStore.getLogout()
    router.push({path:'/'})
 } catch (error) {
   alert('退出登录失败')
 }

}

</script>

<style lang="scss" scoped>
.m-profile {
  height: 3.5rem;
  background-image: url(https://yanxuan.nosdn.127.net/5905098f74e04c39fa5e76ebb9ff591b.png);
  background-size: 100%;
  background-position: bottom;
  padding-left: 0.3rem;
  overflow: hidden;
}

.left {
  display: flex;
  justify-content: space-around;
  flex-wrap: nowrap;

  .info {
    font-size: 14px;
    margin-left: 20px;
    margin-top: 20px;
    color: aliceblue;

    .one {
      font-size: 18px;

    }
  }
}

.m-profile .g-row {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;

  .avatar {
    border-radius: 50%;
    width: 75px;
    height: 75px;
  }
}

.middle {

  .my {
    padding-left: 20px;
    height: 50px;
    line-height: 50px;
    font-size: 14px;

    hr {
      height: 0.5px;
      background-color: #e3dfdf;
    }
  }

  ul {
    height: 80px;
    line-height: 20px;
    display: flex;
    justify-content: space-around;
    flex-wrap: nowrap;
    text-align: center;
    font-size: 14px;

    li {
      margin: 10px;

      p {
        margin: 5px;
      }
    }
  }
  .home{
    height: 10px;
    background-color: rgb(246, 246, 242);
  }
  .bottom{
    height: 20px;
    background-color: rgb(246, 246, 242);
  }
  .last{
    height: 10px;
    background-color: rgb(246, 246, 242);
  }
  .but{
    height: 50px;
  }
}

</style>